package com.zjk.exception;

import com.zjk.Result;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import java.sql.SQLException;

/**
 * @author: gfk
 * @create: 2022/10/28
 * @Description:
 * @FileName: UserExceptionHandler
 * @History:
 * @自定义内容：
 */
@RestControllerAdvice//AOP
//AOP 前置 后置 环绕  返回  异常
public class UserExceptionHandler {

    @ExceptionHandler(Exception.class)
    @ResponseBody
    public Result error(Exception e){
        e.printStackTrace();
        System.out.println("调用了公共异常处理类");
        return new Result(false,0000,e.getMessage());
    }

    @ExceptionHandler(RuntimeException.class)
    @ResponseBody
    public Result runtime(Exception e){
        e.printStackTrace();
        System.out.println("调用了RuntimeException公共异常处理类");
        return new Result(false,0001,
                e.getClass().getName() +"==>" + e.getMessage());
    }

    @ExceptionHandler(SQLException.class)
    @ResponseBody
    public Result sql(Exception e){
        e.printStackTrace();
        System.out.println("调用了SQLException公共异常处理类");
        return new Result(false,0002,e.getMessage());
    }

}